package com.chenfan.mcn.model.base;

import com.baomidou.mybatisplus.annotation.TableField;
import com.chenfan.common.vo.UserVO;
import com.chenfan.mcn.config.UserVoContextHolder;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 租户
 *
 * @author wulg
 * @date 2021-08-21
 **/
@Data
@EqualsAndHashCode(callSuper = true)
public abstract class BaseEntity extends BaseTenantEntity {

    private static final long serialVersionUID = -4405737278089572799L;

    /**
     * 公司id
     */
    @TableField(value="company_id")
    private Long companyId;

    /**
     * 部门id
     */
    @TableField(value="department_id")
    private Long departmentId;

    @Override
    public void init(){
        super.init();
        UserVO userVO = UserVoContextHolder.getUserVo();
        if(userVO != null){
            this.companyId = userVO.getCompanyId();
            this.departmentId = userVO.getDepartmentId();
        }
    }

    @Override
    public void ignore(){
        super.ignore();
        this.companyId = null;
        this.departmentId = null;
    }
}